package ltd.hxya.novel.gateway.config;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.cors.CorsConfiguration;
import org.springframework.web.cors.reactive.CorsWebFilter;
import org.springframework.web.cors.reactive.UrlBasedCorsConfigurationSource;

@Configuration
public class GatewayConfig {

    @Bean
    public CorsWebFilter corsWebFilter(){
        UrlBasedCorsConfigurationSource configurationSource =new UrlBasedCorsConfigurationSource();
        CorsConfiguration corsConfiguration = new CorsConfiguration();
        corsConfiguration.setAllowCredentials(true);
//        corsConfiguration.addAllowedOrigin("http://localhost:1024");
//        corsConfiguration.addAllowedOrigin("http://127.0.0.1:1024");
//        corsConfiguration.addAllowedOrigin("http://localhost:81");
//        corsConfiguration.addAllowedOrigin("http://localhost:9528");
//        corsConfiguration.addAllowedOrigin("http://192.168.65.49:10000");
//        corsConfiguration.addAllowedOrigin("http://192.168.65.50:9528");
        corsConfiguration.addAllowedOrigin("*");
        corsConfiguration.addAllowedHeader("*");
        corsConfiguration.addAllowedMethod("*");
        configurationSource.registerCorsConfiguration("/**",corsConfiguration);
        CorsWebFilter corsWebFilter = new CorsWebFilter(configurationSource);

        return corsWebFilter;
    }
}
